/*********************************页面中所需添加的信息**************************************/
$(function(){

	//当前登录用户的信息
	$('#loginUserName').html(info.getLoginUserObj().username);
	$('#nav-user-photo').attr('src', info.getLoginUserObj().faceImage);
	
	//添加未读留言消息提醒
	var unreadMsg = remind.getUnreadMsg();
	$('#unreadMsgRemind').html(unreadMsg);
})

/*********************************页面中所需添加的信息**************************************/

/********************************* 页面公共信息-开始 *********************************/

// 公共信息
function Info(){
	 this.info = '';
}

//操作描述
Info.prototype.success = '操作成功';
Info.prototype.noAuth = '您无权进行此项操作';
Info.prototype.empty_input = '输入内容为空';

/**
 * 获取当前登录的用户信息
 */										
Info.prototype.getLoginUserObj = function(){
	var userObj;
	$.ajax({
		url: '/admin/sys/user/setLoginUser',
		dataType: 'json',
		type: 'post',
		async: false,
		success: function(obj){
			userObj = obj.data;
		}
	});
	return userObj;
}

// 创建对象，其他页面直接引用，例如：alert(info.noAuth);
var info = new Info();

/********************************* 页面公共信息-结束 *********************************/

/******************************* 页面头部提醒信息-开始 *******************************/
//消息提醒
function Remind(){
	
}
/**
 * 未完成任务提醒
 */
Remind.prototype.getUnfinishedTasks = function getUnfinishedTasks(){
	
}
/**
 * 通知信息提醒
 */
Remind.prototype.getNotification = function getNotification(){
	
}
/**
 * 未读留言信息
 */
Remind.prototype.getUnreadMsg = function getUnreadMsg(){
	var unreadMsgHTML;
	$.ajax({
		url:'/admin/web/message/getUnreadMsg',
		type:'post',
		dataType:'json',
		async:false,
		success:function(obj){
			if(obj.status == 200 && obj.data.length > 0){
				var content = '<a data-toggle="dropdown" class="dropdown-toggle" href="#">'
						+'	<i class="ace-icon fa fa-comment-o icon-animated-wrench"></i>'
						+'	<span class="badge badge-info">' + obj.data.length + '</span>'
						+'</a>'
						+'<ul class="dropdown-menu-right dropdown-navbar navbar-grey dropdown-menu dropdown-caret dropdown-close">'
						+'	<li class="dropdown-header">'
						+'		<i class="ace-icon fa fa-comment-o">您有' + obj.data.length + '条新的留言</i>'
						+'	</li>'
						+'	<li class="dropdown-content">'
						+'<ul class="dropdown-menu dropdown-navbar">';
				
				for(var i in obj.data){
					if(i >= 3) break;//只显示3条
					content += '<li>'
								+'<a href="/admin/web/message/list" class="clearfix">'
								+'	<img src="/static/admin/images/avatars/avatar2.png" class="msg-photo" alt="' + obj.data[i].name + '" />'
								+'	<span class="msg-body">'
								+'		<span class="msg-title" >'
								+'			<span class="blue">' + obj.data[i].name + ': </span>'
								+'			<span>' + obj.data[i].message + '</span>'
								+'		</span>'
								+'		<span class="msg-time">'
								+'			<i class="ace-icon fa fa-clock-o"></i>'
								+'			<span>' + obj.data[i].time + '</span>'
								+'		</span>'
								+'	</span>'
								+'</a>'
							+'</li>';
				}
				
				content += '</ul>'
						+'	</li>'
						+'	<li class="dropdown-footer">'
						+'		<a href="/admin/web/message/list">查看更多留言'
						+'			<i class="ace-icon fa fa-arrow-right"></i>'
						+'		</a>'
						+'	</li>'
						+'</ul>';																				
				unreadMsgHTML = content;
			}
		}
	});
	return unreadMsgHTML;
}
/**
 * 未读邮件提醒
 */
Remind.prototype.getUnreadEmail = function getUnreadEmail(){
	
}
/**
 * 声明remind对象，其他页面引入gweb.js后可以直接调用
 */
var remind = new Remind();
/******************************* 页面头部提醒信息-结束 *******************************/

/******************************** gritter提示框-开始 ********************************/

//成功的提示框
function gritterSuccess(text){
	$.gritter.add({
		title: '系统提示',
		text: text,
		time: 2000,
		class_name: 'gritter-success'
	});
}

//错误的提示框
function gritterError(text){
	$.gritter.add({
		title: '系统提示',
		text: text,
		time: 2000,
		class_name: 'gritter-error'
	});
}

//警告提示框
function gritterWarn(text){
	$.gritter.add({
		title: '系统提示',
		text: text,
		time: 2000,
		class_name: 'gritter-warning'
	});
}

//信息提示框
function gritterInfo(text){
	$.gritter.add({
		title: '系统提示',
		text: text,
		time: 2000,
		class_name: 'gritter-info'
	});
}

//普通默认提示框
function gritterRegular(text){
	$.gritter.add({
		title: '系统提示',
		text: text,
		time: 2000,
		class_name: ''
	});
}
/******************************** gritter提示框-结束 ********************************/
